package com.artwork.service.impl;
import com.artwork.common.enums.JsonResultEnum;
import com.artwork.common.exception.JsonException;
import com.artwork.mapper.SysUserMapper;
import com.artwork.model.SysUser;
import com.artwork.service.SysUserService;
import com.artwork.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author JoJo
 * @Data 2021/9/8$ 14:22$
 * @Description
 * @Param $
 * @Return $
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    SysUserMapper sysUserMapper;
    @Override
    public SysUser selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public List<SysUser> getList(SysUser sysUser) {
        return null;
    }

    @Override
    public SysUser selectByName(String name) {
        return sysUserMapper.selectByName(name);
    }

    @Override
    public SysUser loginAction(String name, String password) throws JsonException {
        SysUser sysUser = sysUserMapper.selectByName(name);
        if (sysUser == null) {
            throw new JsonException(JsonResultEnum.ADMIN_USER_NULL);

        } else if (!MD5Util.string2MD5(password).equals(sysUser.getPassword())) {
            throw new JsonException(JsonResultEnum.ADMIN_PASS_ERROR);
        }
        return sysUser;
    }
}
